package com.honeywen.mymvc.opera;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.io.FileUtils;

import java.io.*;
import java.util.List;
import java.util.Set;

/**
 * @author wangwei
 * @date 2019/11/14
 */
public class FileReadTest3 {


    public static void main(String[] args) {
        // 原来
        String filepath = "/Users/wangwei/test/py/august_origin.txt";

        String filepath1 = "/Users/wangwei/test/py/august_group1.txt";
        String filepath2 = "/Users/wangwei/test/py/august_group2.txt";
        String filepath3 = "/Users/wangwei/test/py/august_group3.txt";
        String filepath4 = "/Users/wangwei/test/py/august_group4.txt";
        String filepath5 = "/Users/wangwei/test/py/august_group5.txt";
        String filepath6 = "/Users/wangwei/test/py/august_group6.txt";
        String filepath7 = "/Users/wangwei/test/py/august_group7.txt";





        File file = new File(filepath);



        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));

            Set<String> list1 = Sets.newHashSet();
            Set<String> list2 = Sets.newHashSet();
            Set<String> list3 = Sets.newHashSet();
            Set<String> list4 = Sets.newHashSet();
            Set<String> list5 = Sets.newHashSet();
            Set<String> list6 = Sets.newHashSet();
            Set<String> list7 = Sets.newHashSet();

            String line = null;
            while ((line = reader.readLine()) != null) {

                line = line.replaceAll("\\s+", " ");
                String[] split = line.split(" ");
                String userId = split[0];
                switch (split[1]) {
                    case "1":
                        list1.add(userId);
                        break;
                    case "2":
                        list2.add(userId);
                        break;
                    case "3":
                        list3.add(userId);
                        break;
                    case "4":
                        list4.add(userId);
                        break;
                    case "5":
                        list5.add(userId);
                        break;
                    case "6":
                        list6.add(userId);
                        break;
                    case "7":
                        list7.add(userId);
                        break;
                    default:
                        break;
                }
            }



            // zu1 20191112

            for (int i = 20191121; i <= 20191125; i++) {
                int[] zu1 = getCount(list1, i);
                int[] zu2 = getCount(list2, i);
                int[] zu3 = getCount(list3, i);
                int[] zu4 = getCount(list4, i);
                int[] zu5 = getCount(list5, i);
                int[] zu6 = getCount(list6, i);
                int[] zu7 = getCount(list7, i);


                System.out.println(i + " -->zu1 applyCnt-->" + zu1[0] + ", loanedcnt-->" + zu1[1]);
                System.out.println(i + " -->zu2 applyCnt-->" + zu2[0] + ", loanedcnt-->" + zu2[1]);
                System.out.println(i + " -->zu3 applyCnt-->" + zu3[0] + ", loanedcnt-->" + zu3[1]);
                System.out.println(i + " -->zu4 applyCnt-->" + zu4[0] + ", loanedcnt-->" + zu4[1]);
                System.out.println(i + " -->zu5 applyCnt-->" + zu5[0] + ", loanedcnt-->" + zu5[1]);
                System.out.println(i + " -->zu6 applyCnt-->" + zu6[0] + ", loanedcnt-->" + zu6[1]);
                System.out.println(i + " -->zu7 applyCnt-->" + zu7[0] + ", loanedcnt-->" + zu7[1]);
                System.out.println("-------------------------");

            }






        } catch (Exception e) {
            e.printStackTrace();
        }

    }



    private static int[] getCount(Set<String> groupUsers, int date) {

        File applyIds = new File("/Users/wangwei/test/ts/1125/apply_" + date+ ".txt");
        File loanedIds = new File("/Users/wangwei/test/ts/1125/loaned_" + date+ ".txt");
        int applyCnt1 = 0;
        int loanedCnt1 = 0;
        try {
            BufferedReader reader11 = new BufferedReader(new InputStreamReader(new FileInputStream(applyIds)));
            BufferedReader reader12 = new BufferedReader(new InputStreamReader(new FileInputStream(loanedIds)));


            String line = null;
            while ((line = reader11.readLine()) != null) {
                if (groupUsers.contains(line)) {
                    applyCnt1++;
                }
            }
            while((line = reader12.readLine()) != null) {
                if (groupUsers.contains(line)) {
                    loanedCnt1 ++;
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

        return new int[] {applyCnt1, loanedCnt1};

    }
}
